package com.lza.phone.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lza.handle.FromTokenGetUser;
import com.lza.phone.entity.Advice;
import com.lza.phone.entity.User;
import com.lza.phone.service.AdviceService;
import com.lza.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李钊澳
 * @since 2021-09-11
 */

@RestController
@RequestMapping("/advice")
public class AdviceController {
    @Autowired
    AdviceService adviceService;
    @Autowired
    FromTokenGetUser fromTokenGetUser;
    @ApiOperation("显示所用用户的建议")
    @ApiOperationSupport(author = "澳神弱爆")
    @GetMapping("showAppAdvice")
    public Result showAllAdvice() {
        List<Advice> list = adviceService.list();
        if (list.isEmpty()) {
            return Result.ok().getMessage("暂时没有用户评论");
        } else {
            return Result.ok().getData("所用用户的评论", list);
        }
    }
    @PostMapping("addAdvice")
    public Result addAdvice(@RequestBody Advice advice){
        User user = fromTokenGetUser.getUser();
        advice.setUserId(user.getId());
        adviceService.save(advice);
        //Result result = showAllAdvice();
        return Result.ok().getMessage("添加评论成功");
    }
    //jhhjhkjhjkhkj
}

